package com.hxkj.controller;

import com.hxkj.domain.po.Navigation;
import com.hxkj.domain.po.NavigationTree;
import com.hxkj.service.NavigationService;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Callable;

/**
 * 栏目控制器
 * <p>
 * Created by chenfangzhou on 2018/6/6.
 */
@RestController
@RequestMapping("/navigation")
public class NavigationController {

    @Autowired
    private NavigationService navigationService;

    /**
     * 获取栏目列表
     *
     * @param navigation
     * @return 翻页数据
     * @throws Exception
     */
    @RequestMapping(value = "/getlist", method = RequestMethod.POST)
    public Callable<List<NavigationTree>> getNavigationList(@ModelAttribute Navigation navigation) throws Exception {
        return () -> (navigationService.getNavigationList(navigation == null ? new Navigation() : navigation)).getData();
    }


    /**
     * 获取单一栏目
     *
     * @param navigation
     * @return Navigation
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public Callable<ResultDataStruct<Navigation>> getNavigation(@ModelAttribute Navigation navigation) throws Exception {
        return () -> navigationService.getNavigation(navigation);
    }

    /**
     * 新增栏目
     *
     * @param navigation
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ResultDataStruct saveNavigation(@ModelAttribute Navigation navigation) throws Exception {
        return navigationService.saveNavigation(navigation);
    }

    /**
     * 删除栏目
     *
     * @param navigation
     * @throws Exception
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public ResultMessageStruct deleteNavigation(@ModelAttribute Navigation navigation) throws Exception {
        return navigationService.deleteNavigation(navigation);
    }

    /**
     * 修改栏目
     *
     * @param navigation
     * @throws Exception
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    public ResultMessageStruct updateNavigation(@ModelAttribute Navigation navigation) throws Exception {
        return navigationService.updateNavigation(navigation);
    }

    /**
     * 更新orderId
     *
     * @throws Exception
     */
    @RequestMapping(value = "/modifyOrderIds")
    public ResultMessageStruct modifyOrderIds(@RequestParam HashMap<String, Object> map) throws Exception {
        return navigationService.modifyOrderIds(map);
    }

}
